﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.SYS.Library;
using ZX.EHR.Library;
using ZX.CRM.Library;

namespace ZX.BLL
{
    public class BDatPhraseDetail : BaseBussnies
    {
        /// <summary>
        /// 根据Value获取字典数据
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<DatPhraseDetail> GetDatPhraseDetailByClassValue(string ClassValue)
        {
            this.entity = new DatPhraseDetail();
            return GetEntitysBySqlComm<DatPhraseDetail>("select  * from DatPhraseDetail where ClassID=(select ClassID from DatPhraseClass where ClassValue='" + ClassValue + "') order by Seq");
        }
        /// <summary>
        /// 获取英才班级数据
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<CrmDeliverHrClass> GetCrmDeliverHrClass()
        {
            this.entity = new CrmDeliverHrClass();
            return GetEntitysBySqlComm<CrmDeliverHrClass>("select ('班级：'+ClassNo+'; 开课时间：'+CONVERT(nvarchar(12), StartTime,111))as ClassNo ,ID from CrmDeliverHrClass where IsCloseClass='0' order by StartTime desc");
        }
        /// <summary>
        /// 获取英才业绩归属部门
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<V_CrmMajorStudentHr> GetOrderDeptName(string termName)
        {
            this.entity = new V_CrmMajorStudentHr();
            return GetEntitysBySqlComm<V_CrmMajorStudentHr>("select distinct OrderDeptName from V_CrmMajorStudentHr where termName='" + termName + "' AND DliverState<>'73DAC2CE-F4BF-403C-9ACC-D075551E3328' order by OrderDeptName");
        }
        /// <summary>
        /// 根据ClassID获取字典数据
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<DatPhraseDetail> GetDatPhraseDetailByClassId(Guid ClassId)
        {
            this.entity = new DatPhraseDetail();
            return GetEntitysBySqlComm<DatPhraseDetail>("select * from DatPhraseDetail where ClassID='" + ClassId + "' order by Seq");
        }
        /// <summary>
        /// 根据PhraseID获取字典数据
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<DatPhraseDetail> GetDatPhraseDetailById(Guid PhraseId)
        {
            this.entity = new DatPhraseDetail();
            return GetEntitysBySqlComm<DatPhraseDetail>("select * from DatPhraseDetail where PhraseID='" + PhraseId + "' order by Seq");
        }
        /// <summary>
        /// 根据PhraseID获取职务
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<DatDutyInfo> GetDatDutyById(Guid PhraseId)
        {
            this.entity = new DatDutyInfo();
            return GetEntitysBySqlComm<DatDutyInfo>("select * from DatDutyInfo where DutyTypeId='" + PhraseId + "' order by SequenceNo");
        }
        /// <summary>
        /// 获取所有产品列表
        /// </summary>
        /// <param name="ClassId">ID</param>
        /// <returns></returns>
        public IList<CrmProduct> GetCrmProduct()
        {
            this.entity = new CrmProduct();
            return GetEntitysBySqlComm<CrmProduct>("select * from CrmProduct where TypeId<>'DBE18F4D-846F-43C5-AA2A-9E3256AAD0FA' order by Caption");
        }
        /// <summary>
        /// 根据ClassID和PhraseText查找记录是否存在
        /// </summary>
        /// <param name="strText">PhraseText</param>
        /// <param name="ClassId">ClassID</param>
        /// <param name="iType">0:新增 1:修改</param>
        /// <returns></returns>
        public bool GetDatPhraseDetailByPhrasaeTextAndClassId(string strText, Guid ClassId, Guid PhraseId, int iType)
        {
            this.entity = new DatPhraseDetail();
            bool temp = false;
            if (iType == 0)
            {
                temp = GetEntityByCondition("PhraseText='" + strText + "' and ClassID='" + ClassId + "'") != null;
            }
            else
            {
                temp = GetEntityByCondition("PhraseID<>'" + PhraseId + "' and ClassID='" + ClassId + "' and PhraseText='" + strText + "'") != null;
            }
            return temp;
        }
    }
}
